﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.DialogUI {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import tool.*;
    import Display.aswingui.*;

    public class OffsetEditorDialog extends GenericDialog {

        private var m_gameObject:GameObject;
        private var m_child:DisplayObject;

        public function OffsetEditorDialog(){
            super("", "", 0, null, "", "", false);
        }
        override protected function onAssetsLoaded(_arg1:Event=null):void{
            var _local2:Dictionary = new Dictionary();
            _local2["dialog_bg"] = (new m_comObject.dialog_bg() as DisplayObject);
            m_jpanel = new OffsetDialogView(_local2);
            finalizeAndShow();
        }
        public function displayOffsets(_arg1:GameObject, _arg2:Boolean=false):void{
            var _local3:MapResource;
            var _local4:Item;
            var _local5:CompositeItemImage;
            var _local6:int;
            var _local7:int;
            var _local8:DisplayObject;
            var _local9:Road;
            var _local10:String;
            var _local11:ItemImageInstance;
            var _local12:Sprite;
            if (!view){
                return;
            };
            if (!_arg1){
                this.m_child = null;
                if (_arg1 != this.m_gameObject){
                    (view as OffsetDialogView).textArea.removeAll();
                    (view as OffsetDialogView).textArea.append(new JLabel("..."));
                    (view as OffsetDialogView).textArea.append(ASwingHelper.verticalStrut(30));
                    (view as GenericDialogView).title.setText("...");
                    ASwingHelper.prepare(view, m_jwindow);
                };
            } else {
                if ((((_arg1 is MapResource)) && (((_arg2) || (!((_arg1 == this.m_gameObject))))))){
                    this.m_child = null;
                    _local3 = (_arg1 as MapResource);
                    _local4 = _local3.getItem();
                    if (_local4){
                        (view as GenericDialogView).title.setText(_local4.name);
                    } else {
                        (view as GenericDialogView).title.setText("null");
                    };
                    _local5 = ((_arg1 as MapResource).getItemImage() as CompositeItemImage);
                    if (_local5){
                        (view as OffsetDialogView).textArea.removeAll();
                        this.makeChildToolset(true, _local5, _arg1, ((_arg2) || (OffsetEditor.captureMode)));
                        _local6 = _local5.numChildren;
                        (view as OffsetDialogView).textArea.removeAll();
                        _local7 = 0;
                        while (_local7 < _local6) {
                            _local8 = _local5.getChildAt(_local7);
                            if (!_local7){
                                this.m_child = _local8;
                            };
                            this.makeChildToolset(false, _local8, _arg1, ((_arg2) || (OffsetEditor.captureMode)));
                            _local7++;
                        };
                        (view as OffsetDialogView).textArea.append(ASwingHelper.verticalStrut(20));
                    } else {
                        (view as OffsetDialogView).textArea.removeAll();
                        this.makeChildToolset(true, (_arg1 as MapResource).getItemImage(), _arg1, ((_arg2) || (OffsetEditor.captureMode)));
                    };
                    if ((_arg1 is Road)){
                        _local9 = (_arg1 as Road);
                        if (_local9 != null){
                            _local10 = _local9.getOverlayImage();
                            _local11 = _local9.getItem().getCachedImage(_local10);
                            if (_local11 != null){
                                _local12 = _local9.getOverlay1();
                                if (((((!((_local12 == null))) && (!((_local12.stage == null))))) && ((_local12.numChildren > 0)))){
                                    this.makeChildToolset(true, _local12.getChildAt(0), _arg1, ((_arg2) || (OffsetEditor.captureMode)));
                                };
                            };
                            _local11 = _local9.getItem().getCachedImage(_local9.getOverlayImage2());
                            if (_local11 != null){
                                _local12 = _local9.getOverlay2();
                                if (((((!((_local12 == null))) && (!((_local12.stage == null))))) && ((_local12.numChildren > 0)))){
                                    this.makeChildToolset(true, _local12.getChildAt(0), _arg1, ((_arg2) || (OffsetEditor.captureMode)));
                                };
                            };
                        };
                    };
                    if (OffsetEditor.captureMode){
                        Global.world.drawAlignmentGrid(_arg1);
                        OffsetEditor.captureMode = false;
                        OffsetEditor.selected = _arg1;
                    };
                    ASwingHelper.prepare((view as OffsetDialogView).textArea, view, m_jwindow);
                };
            };
            this.m_gameObject = _arg1;
        }
        public function checkObject():void{
            if (this.m_child){
                if (!this.m_child.stage){
                    this.displayOffsets(this.m_gameObject, true);
                };
            };
        }
        private function makeChildToolset(_arg1:Boolean, _arg2:DisplayObject, _arg3:GameObject, _arg4:Boolean=false):void{
            (view as OffsetDialogView).textArea.append((_arg4) ? new OffsetEditorMover(_arg2, _arg3, _arg1) : new JLabel(((("x=" + _arg2.x) + "/y=") + _arg2.y)));
        }
        override protected function closeMe(_arg1:Event):void{
            OffsetEditor.active = false;
        }

    }
}//package Display.DialogUI 
